﻿#include "qfaceobject.h"
#include <QDebug>
QFaceObject::QFaceObject(QObject *parent)
    : QObject{parent}
{


    //初始化
    seeta::ModelSetting  FDmode("E:/Environment/SeetaFace/bin/model/fd_2_00.dat",seeta::ModelSetting::CPU,0);
    seeta::ModelSetting  PDmode("E:/Environment/SeetaFace/bin/model/pd_2_00_pts5.dat",seeta::ModelSetting::CPU,0);
    seeta::ModelSetting  FRmode("E:/Environment/SeetaFace/bin/model/fr_2_10.dat",seeta::ModelSetting::CPU,0);
    this->fengineptr = new seeta::FaceEngine(FDmode,PDmode,FRmode);

    //导入已有的人脸数据库
    this->fengineptr->Load("./face.db");
}

QFaceObject::~QFaceObject(){
    delete fengineptr;
}




int64_t QFaceObject::face_register(cv::Mat &faceImage)
{

    //把opencv的Mat数据转为seetaface的数据
    SeetaImageData simage;
    simage.data = faceImage.data;
    simage.width = faceImage.cols;
    simage.height = faceImage.rows;
    simage.channels = faceImage.channels();
    int64_t faceid = this->fengineptr->Register(simage);//注册返回一个人脸id
    qDebug()<<faceid;
    if(faceid>=0){
        fengineptr->Save("./face.db");
    }
    return faceid;
}


int QFaceObject::face_qurrey(cv::Mat &faceImage)
{
    SeetaImageData simage;
    simage.data=faceImage.data;
    simage.width=faceImage.cols;
    simage.height=faceImage.rows;
    simage.channels=faceImage.channels();
    float similarity=0;
    int64_t faceid=fengineptr->Query(simage,&similarity);
    if(similarity>0.7){
        qDebug()<<similarity;
        emit sendFaceid(faceid,similarity);

    }else{
        emit sendFaceid(-1,-1);

    }
}




